home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / QuakeTools / src / libqsys / generic.h.in < prev    next >
Encoding:
Text File  |  1998-06-12  |  3.5 KB  |  160 lines

  1. #ifndef    GENERIC_H
  2. #define    GENERIC_H
  3. #include "rawkeys.h"
  4. #include "rawmouse.h"
  5.  
  6. #ifdef BROKEN_SPRINTF
  7. # undef     sprintf
  8. # define sprintf(str, format, args...) snprintf(str, 256, format, ##args)
  9. #endif /* BROKEN_SPRINTF */
  10.  
  11. #ifdef    __GNUC__
  12. # define __packed __attribute__ ((packed))
  13. #else
  14. # define __packed
  15. #endif
  16.  
  17. typedef enum {            // 
  18.   FALSE, TRUE
  19. } __packed bool;
  20.  
  21. struct rgb {            // 
  22.   unsigned char r, g, b;
  23. } __packed;
  24.  
  25. struct argb {            // 
  26.   unsigned char a;
  27.   struct rgb rgb;
  28. } __packed;
  29.  
  30. struct DisplayDimension {
  31.   bool changedOffset;        // offset of display-device in global desktop (eg. the window on a screen)
  32.   int X, Y;
  33.   bool changedSize;        // size of display-device in global desktop (eg. the window on a screen)
  34.   int Width, Height;
  35.   bool changedDesktopOffset;    // offset of global desktop (eg. the screen)
  36.   int dtX, dtY;
  37.   bool changedDesktopSize;    // size of global desktop (eg. the screen)
  38.   int dtWidth, dtHeight;
  39.   
  40.   bool changedBuffer;        // the actual used framebuffer
  41.   void *frameBuffer;
  42.   int frameSize;
  43.  
  44.  /*
  45.   bool changedPalette;
  46.   struct rgb *Palette;
  47.   */
  48. };
  49.  
  50. extern struct DisplayDimension localDim;
  51.  
  52. /*
  53.  * here are the structs, externals and functions descripted,
  54.  * that could but must not be implemented by the system-drivers
  55.  * the file generic will ever compiled, you can activate
  56.  * your functions with defines
  57.  */
  58.  
  59. #undef    OPENDISPLAY
  60. struct DisplayDimension *OpenDisplay(int width, int height, int depth, struct rgb *Palette);
  61. #undef    SWAPDISPLAY
  62. void *SwapDisplay(void *oldBuffer);
  63. #undef    UPDATEDISPLAY
  64. void *UpdateDisplay(void *oldBuffer, int x, int y, int width, int height);
  65. #undef    CHANGEDISPLAY
  66. struct DisplayDimension *ChangeDisplay(int width, int height, int depth, struct rgb *Palette);
  67. #undef    CLOSEDISPLAY
  68. void CloseDisplay(void);
  69.  
  70. #undef    OPENKEYS
  71. void OpenKeys(void);
  72. #undef    GETKEYS
  73. bool GetKeys(struct keyEvent *eventBuffer);
  74. #undef    CLOSEKEYS
  75. void CloseKeys(void);
  76.  
  77. #undef    OPENMOUSE
  78. void OpenMouse(void);
  79. #undef    GETMOUSE
  80. void GetMouse(struct mouseEvent *eventBuffer);
  81. #undef    CLOSEMOUSE
  82. void CloseMouse(void);
  83.  
  84. void SetDisplay(struct DisplayDimension *dim);
  85.  
  86. /* canonical system */
  87. #include "@target_cpu@/@target_cpu@.h"
  88. #include "@target_cpu@/@target_os@/@target_os@.h"
  89.  
  90. #ifndef    MATCH
  91. unsigned char Match(register struct rgb *rawpix, register struct rgb *Palette);
  92. #endif
  93.  
  94. #ifdef INLINE_BIGENDIAN
  95. #ifndef    SWAPSHORT
  96. #define    SWAPSHORT
  97. static short SwapShort(short l);
  98. static inline short SwapShort(short l) {
  99.   unsigned char b1, b2;
  100.  
  101.   b1 = l & 255;
  102.   b2 = (l >> 8) & 255;
  103.  
  104.   return (b1 << 8) + b2;
  105. }
  106. #endif
  107.  
  108. #ifndef    SWAPLONG
  109. #define    SWAPLONG
  110. static int SwapLong(int l);
  111. static inline int SwapLong(int l) {
  112.   unsigned char b1, b2, b3, b4;
  113.  
  114.   b1 = l & 255;
  115.   b2 = (l >> 8) & 255;
  116.   b3 = (l >> 16) & 255;
  117.   b4 = (l >> 24) & 255;
  118.  
  119.   return ((int)b1 << 24) + ((int)b2 << 16) + ((int)b3 << 8) + b4;
  120. }
  121. #endif
  122.  
  123. #ifndef    SWAPFLOAT
  124. #define    SWAPFLOAT
  125. static float SwapFloat(float l);
  126. static inline float SwapFloat(float l) {
  127.   union {
  128.     unsigned char b[4];
  129.     float f;
  130.   } in, out;
  131.  
  132.   in.f = l;
  133.   out.b[0] = in.b[3];
  134.   out.b[1] = in.b[2];
  135.   out.b[2] = in.b[1];
  136.   out.b[3] = in.b[0];
  137.  
  138.   return out.f;
  139. }
  140. #endif
  141. #endif
  142.  
  143. #if (WORDS_BIGENDIAN == 1)
  144. #define BigShort(a) (a)
  145. #define LittleShort(a) SwapShort(a)
  146. #define BigLong(a) (a)
  147. #define LittleLong(a) SwapLong(a)
  148. #define BigFloat(a) (a)
  149. #define LittleFloat(a) SwapFloat(a)
  150. #else
  151. #define BigShort(a) SwapShort(a)
  152. #define LittleShort(a) (a)
  153. #define BigLong(a) SwapLong(a)
  154. #define LittleLong(a) (a)
  155. #define BigFloat(a) SwapFoat(a)
  156. #define LittleFloat(a) (a)
  157. #endif
  158.  
  159. #endif
  160.